package com.my.config;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.my.properties.GeneratorProperties;
import com.my.service.GenereratorConfigService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author summit
 * @since 2020/6/27 8:46
 */
@ComponentScan("com.my")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(GeneratorProperties.class)
@PropertySource("classpath:application.properties")
public class GeneratorConfig {

    @Bean
    public AutoGenerator autoGenerator(GenereratorConfigService genereratorConfigService) {
        AutoGenerator generator = new AutoGenerator();
        generator.setDataSource(genereratorConfigService.dataSourceConfig());
        generator.setStrategy(genereratorConfigService.strategyConfig());
        generator.setPackageInfo(genereratorConfigService.packageConfig());
        generator.setTemplate(genereratorConfigService.templateConfig());
        // generator.setConfig();
        generator.setGlobalConfig(genereratorConfigService.globalConfig());
         generator.setCfg(genereratorConfigService.injectionConfig());
        //generator.setTemplateEngine(genereratorConfigService.templateConfig());
        return generator;
    }

}
